package com.infitecs.eyas.quality;

import com.infitecs.eyas.constant.Constant;
import com.infitecs.eyas.judge.service.JudgeService;
import com.infitecs.eyas.quality.model.Ash;
import com.infitecs.eyas.quality.model.Industry;
import com.infitecs.eyas.quality.service.AshService;
import com.infitecs.eyas.step.service.StepService;
import com.infitecs.krill.ajax.response.AjaxResponse;
import com.infitecs.krill.ajax.response.ReturnState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * User: chenkaiyu
 * Date: 15-4-25
 * Time: 上午11:09
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/quality/grey/")
public class GreyController {
    @Autowired
    private AshService ashService;

    @Autowired
    private JudgeService judgeService;

    @Autowired
    private StepService stepService;

    @RequestMapping("save")
    public String save(HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        stepService.updateStepStateFinish(caseId,Constant.STEP_ID_3);
        return "redirect:/quality/boom?menuId=11";
    }

    @RequestMapping(value="computer1",method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse calculateOther(HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString());
        String Other = String.valueOf(ashService.calculateE48(caseId));
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
        return new AjaxResponse(Other);
    }

    @RequestMapping(value="total",method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse calculateTotal(HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        String total = String.valueOf(ashService.calculateTotal(caseId));
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
        return new AjaxResponse(total);
    }

    @RequestMapping(value="computer2",method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse calculateRt(HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        String rt= String.valueOf(ashService.calculateE57(caseId));
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
        return new AjaxResponse(rt);
    }

    @RequestMapping(value="computer3",method={RequestMethod.POST})
    @ResponseBody
    public AjaxResponse calculateRz(HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        String rz = String.valueOf(ashService.calculateRz(caseId));
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
        return new AjaxResponse(rz);
    }


    @RequestMapping(value="saveTheValueOfSiO2",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfSiO2(@RequestParam("sio2")double sio2,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfSiO2(sio2,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }


    @RequestMapping(value="saveTheValueOfAl2O3",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfAl2O3(@RequestParam("al2o3")double al2o3,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfAl2O3(al2o3,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfFe2o3",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfFe2o3(@RequestParam("fe2o3")double fe2o3,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfFe2O3(fe2o3,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfCao",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfCao(@RequestParam("cao")double cao,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfCaO(cao,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfTio2",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfTio2(@RequestParam("tio2")double tio2,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfTiO2(tio2,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfMgo",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfMgo(@RequestParam("mgo")double mgo,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfMgO(mgo,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfSo3",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfSo3(@RequestParam("so3")double so3,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfSO3(so3,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfK2O",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfK2O(@RequestParam("k2o")double k2o,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfK2O(k2o,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfNa2o",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfNa2o(@RequestParam("na2o")double na2o,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfNa2O(na2o,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfOther",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfOther(@RequestParam("other")double other,HttpSession httpSession){
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        ashService.saveTheValueOfOther(other,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfDt",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfDt(@RequestParam("dt")double dt,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfDT(dt,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfSt",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfSt(@RequestParam("st")double st,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfST(st,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfHt",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfHt(@RequestParam("ht")double ht,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfHT(ht,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value="saveTheValueOfFt",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfFt(@RequestParam("ft")double ft,HttpSession httpSession){
        int caseId =Integer.parseInt(httpSession.getAttribute("caseId").toString()) ;
        ashService.saveTheValueOfFT(ft,caseId);
        stepService.updateStepStateing(caseId, Constant.STEP_ID_3);
    }

    @RequestMapping(value = "recover", method = RequestMethod.GET)
    @ResponseBody
    public Ash getAsh(HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        return ashService.getAsh(caseId);
    }

    @RequestMapping(value = "ashSave", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResponse ashSave(Ash ash) {
        try {
            ashService.ashSave(ash);
            return new AjaxResponse();
        } catch (Exception e) {
            return new AjaxResponse(ReturnState.ERROR, "请检查填写数据是否有误，操作失败");
        }
    }
}
